package com.demo.common.util;

import com.xiaoleilu.hutool.lang.Console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CMDUtil {

  /**
   * 执行命令方法
   * @param command
   * @throws IOException
   * @throws InterruptedException
   */
  public static void execSync(String command) throws IOException, InterruptedException {
    Console.log("开始执行命令{} ...", command);
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("cmd /c " + command);
    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = null;
    while ((line = br.readLine()) != null) {
      Console.log(line);
    }
    process.waitFor();
    Console.log("执行完毕!");
  }
}
